package com.yunxi.module.system.mapper.social;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.yunxi.framework.mybatis.core.mapper.BaseMapperX;
import com.yunxi.module.system.model.social.SocialUserDO;
import org.apache.ibatis.annotations.Mapper;

/**
 * <p>
 * 社交用户 mapper
 * </p>
 *
 * @author lidy
 * @since 2024-05-08
 */
@Mapper
public interface SocialUserMapper extends BaseMapperX<SocialUserDO> {

    /**
     * 查询社交账号绑定信息
     *
     * @param type  社交平台信息
     * @param code  授权码
     * @param state state
     * @return 绑定信息
     */
    default SocialUserDO selectByTypeAndCodeAnState(Integer type, String code, String state) {
        return selectOne(new LambdaQueryWrapper<SocialUserDO>()
                .eq(SocialUserDO::getType, type)
                .eq(SocialUserDO::getCode, code)
                .eq(SocialUserDO::getState, state));
    }

    /**
     * 根据设计平台类型和社交平台 openid 查询用不绑定信息
     *
     * @param type   社交平台类型
     * @param openid 社交平台 openid
     * @return 社交用户绑定信息
     */
    default SocialUserDO selectByTypeAndOpenid(Integer type, String openid) {
        return selectOne(SocialUserDO::getType, type, SocialUserDO::getOpenid, openid);
    }
}
